+2005-08-30 Øyvind Kolås <pippin@gimp.org>
+
+ * tests/srgb_to_lab_u8.c: updated values.
+ * tests/types.c: rewritten.
+ * tests/models.c: added, a test to test that reference conversions
+ registered for a BablModel are symmetrical.
+ * tests/float_to_u8.c,
+ * tests/u8_to_float.c,
+ * tests/rgb_to_lab_to_rgb.c,
+ * tests/rgb_to_ycbcr_to_rgb.c: removed.
+ * tests/Makefile.am: updated.
+
2005-08-30 Øyvind Kolås <pippin@gimp.org>
* babl/babl-introspect.c:
TESTS = \
- float_to_u8 \
grayscale_to_rgb \
- u8_to_float \
rgb_to_bgr \
- rgb_to_lab_to_rgb \
rgb_to_ycbcr \
- rgb_to_ycbcr_to_rgb \
srgb_to_lab_u8 \
sanity \
types \
+ models \
babl_class_name
-float_to_u8_SOURCES = float_to_u8.c
-u8_to_float_SOURCES = u8_to_float.c
grayscale_to_rgb_SOURCES = grayscale_to_rgb.c
rgb_to_bgr_SOURCES = rgb_to_bgr.c
-rgb_to_lab_to_rgb_SOURCES = rgb_to_lab_to_rgb.c
srgb_to_lab_u8_SOURCES = srgb_to_lab_u8.c
rgb_to_ycbcr_SOURCES = rgb_to_ycbcr.c
-rgb_to_ycbcr_to_rgb_SOURCES = rgb_to_ycbcr_to_rgb.c
babl_class_name_SOURCES = babl_class_name.c
sanity_SOURCES = sanity.c
types_SOURCES = types.c
+models_SOURCES = models.c
AM_CFLAGS = -I$(top_srcdir) -I$(top_srcdir)/babl
+++ /dev/null
-/* babl - dynamically extendable universal pixel conversion library.
- * Copyright (C) 2005, Øyvind Kolås.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#include "babl.h"
-#include "babl-internal.h"
-
-#define BUFFER_LENGTH 6
-
-float float_buf[BUFFER_LENGTH]=
-{
- 0.0,
- 1.0,
- -1.0,
- 2.0,
- 0.5,
- 0.25,
-};
-
-unsigned char u8_buf [BUFFER_LENGTH];
-unsigned char u8_ref_buf [BUFFER_LENGTH]=
-{
- 0,
- 255,
- 0,
- 255,
- 127,
- 63,
-};
-
-int
-test_float_to_rgb_u8 (void)
-{
- Babl *fish;
- int i;
- int OK=1;
-
-
- fish = babl_fish (
- babl_format_new (
- babl_model ("Y"),
- babl_type ("float"),
- babl_component ("Y"),
- NULL
- ),
- babl_format_new (
- babl_model ("Y"),
- babl_type ("u8"),
- babl_component ("Y"),
- NULL
- ));
-
- babl_process (fish,
- float_buf, u8_buf,
- BUFFER_LENGTH);
-
- for (i=0; i<BUFFER_LENGTH; i++)
- {
- if (u8_buf[i] != u8_ref_buf[i])
- OK=0;
- }
- if (!OK)
- return -1;
- return 0;
-}
-
-int
-main (int argc,
- char **argv)
-{
- babl_init ();
- if (test_float_to_rgb_u8 ())
- return -1;
- babl_destroy ();
- return 0;
-}
-
-
-
--- /dev/null
+/* perform a symmetricality of conversion test on a set of randomized
+ * RGBA data */
+
+#include <stdlib.h>
+#include "babl.h"
+#include "math.h"
+#include "babl-internal.h"
+
+int OK=1;
+
+#define pixels 1024
+#define TOLERANCE 0.001
+
+double test[pixels * 4];
+
+double r_interval (double min, double max)
+{
+ long int rand_i = random ();
+ double ret;
+ ret = (double) rand_i / RAND_MAX;
+ ret*=(max-min);
+ ret+=min;
+ return ret;
+}
+
+void test_init (void)
+{
+ double r_min = -0.2,
+ r_max = 1.5,
+ g_min = -0.2,
+ g_max = 1.5,
+ b_min = -0.2,
+ b_max = 1.5,
+ a_min = -0.5,
+ a_max = 1.5;
+ int i;
+ double r,g,b,a;
+ for (i=0;i<pixels;i++)
+ {
+ r=r_interval(r_min, r_max);
+ g=r_interval(g_min, g_max);
+ b=r_interval(b_min, b_max);
+ a=r_interval(a_min, a_max);
+ test [i*4 + 0]=r;
+ test [i*4 + 1]=g;
+ test [i*4 + 2]=b;
+ test [i*4 + 3]=a;
+ }
+}
+
+
+static Babl *reference_format (void)
+{
+ static Babl *self = NULL;
+
+ if (!self)
+ self = babl_format_new (
+ babl_model ("RGBA"),
+ babl_type ("double"),
+ babl_component ("R"),
+ babl_component ("G"),
+ babl_component ("B"),
+ babl_component ("A"),
+ NULL);
+ return self;
+}
+
+static Babl *construct_double_format (Babl *model)
+{
+ void *argument[42+1];
+ int args = 0;
+ int i;
+
+ argument[args++] = model;
+ argument[args++] = babl_type ("double");
+
+ for (i=0;i<model->model.components; i++)
+ {
+ argument[args++] = model->model.component[i];
+ }
+ argument[args++] = NULL;
+
+#define o(argno) argument[argno],
+ return babl_format_new (o(0) o(1) o(2) o(3)
+ o(4) o(5) o(6) o(7)
+ o(8) o(9) o(10) o(11)
+ o(12) o(13) o(14) o(15)
+ o(16) o(17) o(18) o(19)
+ o(20) o(21) o(22) o(23)
+ o(24) o(25) o(26) o(27)
+ o(28) o(29) o(30) o(31)
+ o(32) o(33) o(34) o(35)
+ o(36) o(37) o(38) o(39)
+ o(40) o(41) o(42) NULL);
+#undef o
+}
+
+int model_check (Babl *babl,
+ void *userdata)
+{
+ void *original;
+ double *clipped;
+ void *destination;
+ double *transformed;
+
+ Babl *ref_fmt;
+ Babl *fmt;
+ Babl *fish_to;
+ Babl *fish_from;
+
+ ref_fmt = reference_format ();
+ fmt = construct_double_format (babl);
+ fish_to = babl_fish (ref_fmt, fmt);
+ fish_from = babl_fish (fmt, ref_fmt);
+
+ original = babl_calloc (1,64/8 * babl->model.components * pixels);
+ clipped = babl_calloc (1,64/8 * 4 * pixels);
+ destination = babl_calloc (1,64/8 * babl->model.components * pixels);
+ transformed = babl_calloc (1,64/8 * 4 * pixels);
+
+ babl_process (fish_to, test, original, pixels);
+ babl_process (fish_from, original, clipped, pixels);
+ babl_process (fish_to, clipped, destination, pixels);
+ babl_process (fish_from, destination, transformed, pixels);
+
+ {
+ int i;
+ int log=0;
+
+ for (i=0;i<pixels;i++)
+ {
+ int j;
+ for (j=0;j<4;j++)
+ if (fabs (clipped[i*4+j] - transformed[i*4+j])>TOLERANCE)
+ {
+ log=1;
+ OK=0;
+ }
+ if (log && log < 5)
+ {
+ babl_log ("%s", babl->instance.name);
+ babl_log ("\ttest: %2.3f %2.3f %2.3f %2.3f", test [i*4+0],
+ test [i*4+1],
+ test [i*4+2],
+ test [i*4+3]);
+ babl_log ("\tclipped: %2.3f %2.3f %2.3f %2.3f", clipped [i*4+0],
+ clipped [i*4+1],
+ clipped [i*4+2],
+ clipped [i*4+3]);
+ babl_log ("\ttrnsfrmd: %2.3f %2.3f %2.3f %2.3f", transformed [i*4+0],
+ transformed [i*4+1],
+ transformed [i*4+2],
+ transformed [i*4+3]);
+ log++;
+ OK=0;
+ }
+ }
+ }
+
+ babl_free (original);
+ babl_free (clipped);
+ babl_free (destination);
+ babl_free (transformed);
+ return 0;
+}
+
+int main (void)
+{
+ babl_init ();
+ test_init ();
+
+ babl_set_extender (babl_extension_quiet_log ());
+ babl_model_each (model_check, NULL);
+
+ babl_destroy ();
+
+ return !OK;
+}
+++ /dev/null
-/* babl - dynamically extendable universal pixel conversion library.
- * Copyright (C) 2005, Øyvind Kolås.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-
-#include <math.h>
-#include "babl.h"
-#include "babl-internal.h"
-
-#define PIXELS 32
-#define TOLERANCE 0.001
-
-float source_buf [PIXELS*3]=
- {1.0, 1.0, 1.0,
- 1.0, 1.0, 1.0,
- 0.0, 1.0, 1.0,
- 0.0, 1.0, 0.0,
- 1.0, 0.0, 1.0,
- 1.0, 0.0, 0.0,
- 1.0, 0.0, 1.0,
- 0.0, 0.0, 0.0,
-
- 0.75, 0.75, 0.75,
- 0.75, 0.75, 0.75,
- 0.0, 0.75, 0.75,
- 0.0, 0.75, 0.0,
- 0.75, 0.0, 0.75,
- 0.75, 0.0, 0.0,
- 0.75, 0.0, 0.75,
- 0.0, 0.0, 0.0,
-
- 0.5, 0.5, 0.5,
- 0.5, 0.5, 0.5,
- 0.0, 0.5, 0.5,
- 0.0, 0.5, 0.0,
- 0.5, 0.0, 0.5,
- 0.5, 0.0, 0.0,
- 0.5, 0.0, 0.5,
- 0.0, 0.0, 0.0,
-
- 0.25, 0.25, 0.25,
- 0.25, 0.25, 0.25,
- 0.0, 0.25, 0.25,
- 0.0, 0.25, 0.0,
- 0.25, 0.0, 0.25,
- 0.25, 0.0, 0.0,
- 0.25, 0.0, 0.25,
- 0.0, 0.0, 0.0
- };
-
-float temp_buf [PIXELS*3];
-float destination_buf [PIXELS*3];
-
-int
-test (void)
-{
- Babl *fish;
- int i;
- int OK=1;
-
-
- fish = babl_fish (
- babl_format_new (
- "name", "foo",
- babl_model ("RGB"),
- babl_type ("float"),
- babl_component ("R"),
- babl_component ("G"),
- babl_component ("B"),
- NULL
- ),
- babl_format_new (
- "name", "bar",
- babl_model ("CIE Lab"),
- babl_type ("float"),
- babl_component ("CIE L"),
- babl_component ("CIE a"),
- babl_component ("CIE b"),
- NULL
- )
- );
-
- babl_process (fish, source_buf, temp_buf, PIXELS);
-
- /* this test tests both pixel format creation, and the scope of
- * babl_fish()'s polymorphism
- */
- fish = babl_fish ("bar","foo");
-
- babl_process (fish, temp_buf, destination_buf, PIXELS);
-
- for (i=0; i<PIXELS * 3; i++)
- {
- if (fabs(destination_buf[i] - source_buf[i]) > TOLERANCE)
- {
- babl_log ("%2i (%2i%%3=%i, %2i/3=%i) is %f should be %f",
- i, i,i%3, i,i/3, destination_buf[i], source_buf[i]);
- OK=0;
- }
- }
-
- if (!OK)
- return -1;
- return 0;
-}
-
-int
-main (int argc,
- char **argv)
-{
- babl_init ();
- if (test())
- return -1;
- babl_destroy ();
- return 0;
-}
+++ /dev/null
-/* babl - dynamically extendable universal pixel conversion library.
- * Copyright (C) 2005, Øyvind Kolås.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-
-#include <math.h>
-#include "babl.h"
-#include "babl-internal.h"
-
-#define PIXELS 6
-#define TOLERANCE 0.00002
-
-float source_buf [PIXELS*3]=
- {0.0, 0.0, 0.0,
- 0.5, 0.5, 0.5,
- 1.0, 1.0, 1.0,
- 1.0, 0.0, 0.0,
- 0.0, 1.0, 0.0,
- 0.0, 0.0, 1.0};
-
-float temp_buf [PIXELS*3];
-float destination_buf [PIXELS*3];
-
-int
-test (void)
-{
- Babl *fish;
- int i;
- int OK=1;
-
- fish = babl_fish (
- babl_format_new (
- "name", "foo",
- babl_model ("RGB"),
- babl_type ("float"),
- babl_component ("R"),
- babl_component ("G"),
- babl_component ("B"),
- NULL
- ),
- babl_format_new (
- "name", "bar",
- babl_model ("Y'CbCr"),
- babl_type ("float"),
- babl_component ("Y'"),
- babl_component ("Cb"),
- babl_component ("Cr"),
- NULL
- )
- );
-
- babl_process (fish, source_buf, temp_buf, PIXELS);
-
- fish = babl_fish (babl_format ("bar"),
- babl_format ("foo"));
-
- babl_process (fish, temp_buf, destination_buf, PIXELS);
-
- for (i=0; i<PIXELS * 3; i++)
- {
- if (fabs(destination_buf[i] - source_buf[i]) > TOLERANCE)
- {
- babl_log ("%2i (%2i%%3=%i, %2i/3=%i) is %f should be %f",
- i, i,i%3, i,i/3, destination_buf[i], source_buf[i]);
- OK=0;
- }
- }
- if (!OK)
- return -1;
- return 0;
-}
-
-int
-main (int argc,
- char **argv)
-{
- babl_init ();
- if (test())
- return -1;
- babl_destroy ();
- return 0;
-}
unsigned char reference_buf [PIXELS*3]=
{ 0, 128, 128,
- 135, 128, 128,
- 255, 128, 128,
- 135, 208, 195,
- 223, 41, 211,
- 82, 207, 20};
+ 135, 128, 127,
+ 254, 127, 128,
+ 135, 207, 195,
+ 222, 42, 210,
+ 81, 206, 20};
unsigned char destination_buf [PIXELS*3];
int OK=1;
-double test[] = {
- 0.0, 0.5, 1.0, 0.1, 0.9, 1.1, -0.1, -2, 2.0, 100, -100, 200, 200
-};
+#define TOLERANCE 0.0046
+#define samples 2048
+double test[samples];
-int samples = sizeof(test) / sizeof(test[0]);
+double r_interval (double min, double max)
+{
+ long int rand_i = random ();
+ double ret;
+ ret = (double) rand_i / RAND_MAX;
+ ret*=(max-min);
+ ret+=min;
+ return ret;
+}
+void test_init (double min, double max)
+{
+ int i;
+ for (i=0;i<samples;i++)
+ {
+ test [i]=r_interval(min,max);
+ }
+}
static Babl *double_vector_format (void)
{
static Babl *self = NULL;
int type_check (Babl *babl,
void *userdata)
{
+
+
void *original;
double *clipped;
void *destination;
double *transformed;
+ Babl *ref_fmt;
Babl *fmt;
+ Babl *fish_to;
+ Babl *fish_from;
-
- original = babl_calloc (1,babl->type.bits/8 * samples);
- clipped = babl_calloc (1,64/8 * samples);
- destination = babl_calloc (1,babl->type.bits/8 * samples);
- transformed = babl_calloc (1,64/8 * samples);
-
+ ref_fmt = double_vector_format ();
fmt = babl_format_new (babl_model ("Y"),
babl,
babl_component ("Y"),
NULL);
+ fish_to = babl_fish (ref_fmt, fmt);
+ fish_from = babl_fish (fmt, ref_fmt);
- babl_process (babl_fish (double_vector_format (), fmt),
- test, original, samples);
- babl_process (babl_fish (fmt, double_vector_format ()),
- original, clipped, samples);
- babl_process (babl_fish (double_vector_format (), fmt),
- clipped, destination, samples);
- babl_process (babl_fish (fmt, double_vector_format ()),
- destination, transformed, samples);
+ original = babl_calloc (1,babl->type.bits/8 * samples);
+ clipped = babl_calloc (1,64/8 * samples);
+ destination = babl_calloc (1,babl->type.bits/8 * samples);
+ transformed = babl_calloc (1,64/8 * samples);
+
+ babl_process (fish_to, test, original, samples);
+ babl_process (fish_from, original, clipped, samples);
+ babl_process (fish_to, clipped, destination, samples);
+ babl_process (fish_from, destination, transformed, samples);
+
{
+ int cnt=0;
int i;
for (i=0;i<samples;i++)
{
- if (fabs (clipped[i] - transformed[i])>0.00001)
- babl_log ("%s: %f %f %f)",
- babl->instance.name, test[i], clipped[i], transformed[i]
- );
- OK=0;
+ if (fabs (clipped[i] - transformed[i])> TOLERANCE)
+ {
+ if (cnt++<4)
+ babl_log ("%s: %f %f %f)",
+ babl->instance.name, test[i], clipped[i], transformed[i]
+ );
+ OK=0;
+ }
}
}
{
babl_init ();
+ test_init (0.0, 182.0);
+
babl_set_extender (babl_extension_quiet_log ());
babl_type_each (type_check, NULL);
+ babl_introspect (NULL);
babl_destroy ();
return !OK;
+++ /dev/null
-/* babl - dynamically extendable universal pixel conversion library.
- * Copyright (C) 2005, Øyvind Kolås.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#include "babl.h"
-#include <math.h>
-#include "babl-internal.h"
-
-#define BUFFER_LENGTH 4
-#define TOLERANCE 0.003
-
-unsigned char u8_buf [BUFFER_LENGTH]= { 0, 255, 127, 63, };
-float float_ref_buf[BUFFER_LENGTH] = { 0.0, 1.0, 0.5, 0.25, };
-float float_buf [BUFFER_LENGTH];
-
-int
-test (void)
-{
- Babl *fish;
- int i;
- int OK=1;
-
-
- fish = babl_fish (
- babl_format_new (
- babl_model ("Y"),
- babl_type ("u8"),
- babl_component ("Y"),
- NULL
- ),
- babl_format_new (
- babl_model ("Y"),
- babl_type ("float"),
- babl_component ("Y"),
- NULL
- ));
-
- babl_process (fish,
- u8_buf, float_buf,
- BUFFER_LENGTH);
-
- for (i=0; i<BUFFER_LENGTH; i++)
- {
- if (fabs (float_buf[i] - float_ref_buf[i]) > TOLERANCE)
- {
- babl_log ("%i .. %f-%f=%f",
- u8_buf[i], float_buf[i], float_ref_buf[i],
- fabs (float_buf[i] - float_ref_buf[i])
- );
- OK=0;
- }
- }
- if (!OK)
- return -1;
- return 0;
-}
-
-int
-main (int argc,
- char **argv)
-{
- babl_init ();
- if (test())
- return -1;
- babl_destroy ();
- return 0;
-}
-
-
-